ABC169 D - Div Game
https://atcoder.jp/contests/abc169/tasks/abc169_d
提出
code: python
import itertools
n = int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp % i == 0:
cnt = 0
while temp %i ==0:
cnt += 1
temp //= i
arr.append(i, cnt)
if temp != 1:
arr.append(temp, 1)
if arr == []:
arr.append(n, 1)
return arr
# print(factorization(n))
# a, b のaは必ず素数になる
nums = set()
for i in factorization(n):
for j in range(1, i1+1):
nums.add(i0 ** j)
for i in itertools.permutations(nums, len(nums)):
# (36954241, 5, 4, 2, 9, 3, 8, 25, 125, 6079, 27) 多すぎる
解答
code: python
from collections import Counter
n = int(input())
def prime_factorization(n):
table = []
for x in range(2, int(n ** 0.5) + 1):
while n % x == 0:
table.append(x)
n //= x
if n > 1:
table.append(n)
return table
# print(prime_factorization(n))
# 2, 2, 2, 3
c = Counter(prime_factorization(n))
# print(Counter(prime_factorization(n)))
# Counter({2: 3, 3: 1})
ans = 0
for i in c.values():
# 1個使う
nx = 1
while (i >= nx):
i -= nx
ans += 1
# 2個使う...
nx += 1
print(ans)
テーマ
#primeDecomposition
提出
code: python
n = int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append(i, cnt)
if temp!=1:
arr.append(temp, 1)
if arr==[]:
arr.append(n, 1)
return arr
factor = factorization(n)
# print(factor)
# z全部挙げられる?
# どれをpikupするか
# ~/Desktop/python_playground
# $ python3 -u "/Users/wafuwafu13/Desktop/python_playground/index.py"
# 810
# 2, 1], 3, 4, [5, 1
# ~/Desktop/python_playground
# $ python3 -u "/Users/wafuwafu13/Desktop/python_playground/index.py"
# 405
# 3, 4], [5, 1
# 何個取るか 別個に取ることは考えないでいい? <- メリットがない
# 1 -> 1 2 -> 3 3 -> 6 4 -> 10
# 高々15
ans = 0
for f in factor:
if f0 == 1:
continue
for i in range(1, 16):
if f1 - i >= 0:
ans += 1
f1 -= i
else:
break
print(ans)